<?php

namespace App\Http\Middleware;

use Closure;
use Session;
use App\sw_manager;
use App\sw_role;
use App\sw_auth;
class QuanMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {    $name=Session::get('mg_name');
    
        if ($name==null) {
        return redirect('Admin/login');
        }
        if ($name=='admin') {
            return $next($request); 
        }
        $mg=sw_manager::where('mg_name',$name)->select('mg_role_id')->first();
        if ($mg->mg_role_id!=0) {
           $role=sw_role::find($mg->mg_role_id);
           $url=$role->auth_luyou.',index,home';
           $arr=explode(',', $url);
           foreach ($arr as $v) {
               $ff=str_contains($request->url(),$v);
                if ($ff) {
                    return $next($request);
                }  
            }  
           } 
     return '您没有这个权限'; 
        
    }
}
